package com.flash.BusinessParameters.service.impl;

import com.flash.BusinessParameters.entity.Security;
import com.flash.BusinessParameters.mapper.SecurityMapper;
import com.flash.BusinessParameters.service.SecurityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SecurityServiceImpl implements SecurityService {
    @Autowired
    SecurityMapper securityMapper;
    @Override
    public List<Security> selectSecurity() {
        return securityMapper.selectSecurity();
    }

    @Override
    public int deleteSecurity(String SecurityId) {
        return securityMapper.deleteSecurity(SecurityId);
    }

    @Override
    public int insertSecurity(Security security) {
        return securityMapper.insertSecurity(security);
    }

    @Override
    public int updateSecurity(Security security) {
        return securityMapper.updateSecurity(security);
    }
    @Override
    public int selectCountSecurity(){
        return securityMapper.selectCountSecurity();
    }
    public String buildStrWhere(Security security){
        StringBuffer strWhere=new StringBuffer("");
        if(security.getSecurityId()!=null && !security.getSecurityId().equals(""))
        {
            strWhere.append(" and securityId like '%" + security.getSecurityId() + "%'");
        }
        if(security.getSecurityName()!=null && !security.getSecurityName().equals(""))
        {
            strWhere.append(" and securityName like '%" + security.getSecurityName() + "%'");
        }
        if (security.getSecurityType()!=0)
        {
            strWhere.append(" and securityType =" + security.getSecurityType());
        }

        return strWhere.toString();
    }


    @Override
    public List<Security> selectSec(Security security) {
        HashMap<Object, Object> map = new HashMap<>();
        map.put("strWhere",buildStrWhere(security));
        List<Security> securities = securityMapper.selectSec(map);
        return securities;
    }
}
